package com.bd.model;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

import javax.faces.bean.ManagedBean;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

@Entity
@Table
@ManagedBean(name = "cd")
public class CD {

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Integer		id;

	@OneToOne
	@JoinColumn(name = "fkLabel")
	private Label		fkLabel;
	private String		descricao;
	private BigDecimal	preco;
	private Date		dataCompra;
	private Date		dataGravacao;

	@OneToMany(fetch = FetchType.LAZY, mappedBy = "fkCd")
	private Set<Faixa>	teste;

	public CD() {
		// TODO Auto-generated constructor stub
	}

	/**
	 * @return the codigo
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @param codigo
	 *            the codigo to set
	 */
	public void setId(Integer codigo) {
		this.id = codigo;
	}

	/**
	 * @return the fkLabel
	 */
	public Label getFkLabel() {
		return fkLabel;
	}

	/**
	 * @param fkLabel
	 *            the fkLabel to set
	 */
	public void setFkLabel(Label fkLabel) {
		this.fkLabel = fkLabel;
	}

	/**
	 * @return the descricao
	 */
	public String getDescricao() {
		return descricao;
	}

	/**
	 * @param descricao
	 *            the descricao to set
	 */
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

	/**
	 * @return the preco
	 */
	public BigDecimal getPreco() {
		return preco;
	}

	/**
	 * @param preco
	 *            the preco to set
	 */
	public void setPreco(BigDecimal preco) {
		this.preco = preco;
	}

	/**
	 * @return the dataCompra
	 */
	public Date getDataCompra() {
		return dataCompra;
	}

	/**
	 * @param dataCompra
	 *            the dataCompra to set
	 */
	public void setDataCompra(Date dataCompra) {
		this.dataCompra = dataCompra;
	}

	/**
	 * @return the dataGravacao
	 */
	public Date getDataGravacao() {
		return dataGravacao;
	}

	/**
	 * @param dataGravacao
	 *            the dataGravacao to set
	 */
	public void setDataGravacao(Date dataGravacao) {
		this.dataGravacao = dataGravacao;
	}

	public void setTeste(Set<Faixa> teste) {
		this.teste = teste;
	}

	public Set<Faixa> getTeste() {
		return teste;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		CD other = (CD) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return descricao;
	}
}
